	<include file='Common:header' />

		<!-- /section:basics/navbar.layout -->
		<div class="main-container" id="main-container">

			<!-- #section:basics/sidebar -->

	<include file='Common:left' />
			<!-- /section:basics/sidebar -->
			
			<div class="main-content">
				<div class="main-content-inner">
					<div class="page-content">
						<div class="row maintop">
							<form class="form-horizontal" name="admin_rule_add" id="admin_rule_add" method="post" action="{:U('admin_rule_add')}">
								<div class="col-xs-12 col-sm-12">
								<small>菜单状态：</small>
								<small>
									<select name="status">
										<option value="1">显示</option>
										<option value="0">不显示</option>
									</select>
								</small>
								<small class="sl-left10">父级：</small>
								<small>
									<select name="pid">
										<option value="0">--默认顶级--</option>
											<foreach name="admin_rule" item="v">
												<option value="{$v.id}" style="margin-left:55px;">{$v.lefthtml}{$v.title}</option>
											</foreach>
									</select>
								</small>
								<small class="sl-left10">名称：</small>
								<small><input name="title" id="title" class="rule"  placeholder=" 输入名称" /></small>
								<small class="sl-left10">控/方：</small>
								<small><input name="name" id="name" class="rule"  placeholder=" 输入控制器/方法" /></small>
								<small class="sl-left10">css：</small>
								<small><input name="css" id="css" class="wh50"  placeholder=" css样式" /></small>
								<small class="sl-left10">排序：</small>
								<small><input name="sort" id="sort" class="wh30" value="50"/></small>
								<small>
								<button class="btn btn-xs btn-danger ruleadd">
										添加权限
								</button>
								</small>
								</div>
							</form>
						<div class="col-xs-12 col-sm-12 rule-top alert alert-info top10">
						<button type="button" class="close" data-dismiss="alert">
							<i class="ace-icon fa fa-times"></i>
						</button>
						1、《控/方》：意思是 控制器/方法; 例如 Sys/sys_list<br />
						2、css为控制左侧导航顶级栏目前图标样式，具体可查看FontAwesome图标CSS样式
						</div>
							<div class="row">
							    <div class="col-xs-12">
										<div>
											<form id="ruleorder" name="ruleorder" method="post" action="{:U('ruleorder')}" >
											<table width="100%" class="table table-striped table-bordered table-hover" id="dynamic-table">
												<thead>
													<tr>
													  <th width="8%">ID</th>
													  <th width="21%">权限名称</th>
													  <th width="13%">控制器/方法</th>
													  <th width="13%">是否验证权限</th>
													  <th width="13%">栏目菜单状态</th>
													  <th width="8%" style="border-right:#CCC solid 1px;">排序</th>
													  <th width="11%" style="border-right:#CCC solid 1px;">操作</th>
												  </tr>
												</thead>

												<tbody>

                                                <foreach name="admin_rule" item="v">
													<tr>
														<td height="28">{$v.id}</td>
														<td style='padding-left:<if condition="$v.leftpin neq 0">{$v.leftpin}px</if>' >{$v.lefthtml}{$v.title}</td>
														<td>{$v.name}</td>
														<td>
														<if condition='$v[authopen] eq 1'>
														<a class="red" href="javascript:;" onclick="return tzyes({$v.id});" title="已开启">
														<div id="yz{$v.id}"><button class="btn btn-minier btn-danger">无需验证</button></div>
														</a>
														<else/>
														<a class="red" href="javascript:;" onclick="return tzyes({$v.id});" title="已禁用">
														<div id="yz{$v.id}"><button class="btn btn-minier btn-yellow">需要验证</button></div>
														</a>														</if>														</td>
														<td>
														<if condition='$v[menustatus] eq 1'>
														<a class="red" href="javascript:;" onclick="return stateyes({$v.id});" title="已开启">
														<div id="zt{$v.id}"><button class="btn btn-minier btn-yellow">显示状态</button></div>
														</a>
														<else/>
														<a class="red" href="javascript:;" onclick="return stateyes({$v.id});" title="已禁用">
														<div id="zt{$v.id}"><button class="btn btn-minier btn-danger">隐藏状态</button></div>
														</a>														</if>														</td>
														<td><input name="{$v.id}" class="list_order" value=" {$v.sort}" size="10"/></td>
														<td>
						<div class="hidden-sm hidden-xs action-buttons">
							<a class="green" href="{:U('admin_rule_edit',array('id'=>$v['id']))}" title="修改">
								<i class="ace-icon fa fa-pencil bigger-130"></i>							</a>
							<a class="red" href="javascript:;" onclick="return del({$v.id});" title="删除">
								<i class="ace-icon fa fa-trash-o bigger-130"></i>							</a>						</div>														</td>
													</tr>
                                                 </foreach>   
                                                  <tr>
													  <td colspan="8" align="left"><button type="submit"  id="btnorder" class="btn btn-white btn-yellow btn-sm">排序</button></td>
												  </tr>
												</tbody>
										  </table>
										  </form>
							    		</div>


<include file='Common:header_nav' />
>

<script>
function del(id){
		layer.confirm('你确定要删除吗？', {icon: 3}, function(index){
	    layer.close(index);
	    window.location.href="__URL__/admin_rule_del/id/"+id+"";
	});
}

function stateyes(val){
		  $.post('{:U("admin_rule_state")}',
		  {x:val},
	function(data){
		if(data.status){
			if(data.info=='状态禁止'){
				var a='<button class="btn btn-minier btn-danger">隐藏状态</button>'
				$('#zt'+val).html(a);
				return false;
			}else{
				var b='<button class="btn btn-minier btn-yellow">显示状态</button>'
				$('#zt'+val).html(b);
				return false;
			}
		}
	});
	return false;
}


function tzyes(val){
		  $.post('{:U("admin_rule_tz")}',
		  {x:val},
	function(data){
		if(data.status){
			if(data.info=='无需验证'){
				var a='<button class="btn btn-minier btn-danger">无需验证</button>'
				$('#yz'+val).html(a);
				return false;
			}else{
				var b='<button class="btn btn-minier btn-yellow">需要验证</button>'
				$('#yz'+val).html(b);
				return false;
			}
		}
	});
	return false;
}

$(function(){
	$('#admin_rule_add').ajaxForm({
		beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
		success: complete, // 这是提交后的方法
		dataType: 'json'
	});
	
	function checkForm(){
		if( '' == $.trim($('#title').val())){
			layer.alert('名称不能为空', {icon: 6}, function(index){
 			layer.close(index);
			$('#title').focus(); 
			});
			return false;
		}
		
		if( '' == $.trim($('#name').val())){
			layer.alert('控制器/方法不能为空', {icon: 6}, function(index){
 			layer.close(index);
			$('#name').focus(); 
			});
			return false;
		}
 }
	function complete(data){
		if(data.status==1){
			layer.alert(data.info, {icon: 6}, function(index){
 			layer.close(index);
			window.location.href=data.url;
			});
		}else{
			alert(data.info);
			return false;	
		}
	}
 
});



$(function(){
	$('#ruleorder').ajaxForm({
		success: complete, // 这是提交后的方法
		dataType: 'json'
	});


	function complete(data){
		if(data.status==1){
			layer.alert(data.info, {icon: 6}, function(index){
 			layer.close(index);
			window.location.href=data.url;
			});
		}else{
			layer.alert(data.info, {icon: 6}, function(index){
 			layer.close(index);
			window.location.href=data.url;
			});
		}
	}
});

</script>
					</div><!-- /.page-content -->
				</div>
			</div><!-- /.main-content -->
	<include file='Common:footer' />
    
		</div><!-- /.main-container -->
	</body>
</html>
